import Router from 'koa-router';
import  users from './controllers/user.js'
import { roles } from './controllers/role.js'

const router = new Router();

console.log(users);

for (let item in users) {
    let tmpArr = item.split(' ');
    let method = tmpArr[0];
    let path = tmpArr[1];
    let fn = users[item];
    // 使用路由来注册对应的请求方式（get、post、put、delete）、路径、处理函数
    router[method](path, fn);

}

for (let item in roles) {

    let tmpArr = item.split(' ');
    let method = tmpArr[0];
    let path = tmpArr[1];
    let fn = roles[item];
    router[method](path, fn);

}


/*
    1.使用fs模块，扫描指定目录下的所有文件，这里是指controllers
    2.遍历所有文件，一个个处理当前js文件
    3.导入当前js文件对应的模块

*/



export let routerMiddle = router.routes();

